<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="计量单主表id" prop="settleId">
        <el-input
          v-model="queryParams.settleId"
          placeholder="请输入计量单主表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同清单项id" prop="cSheetId">
        <el-input
          v-model="queryParams.cSheetId"
          placeholder="请输入合同清单项id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期完成容量" prop="bqWcrl">
        <el-input
          v-model="queryParams.bqWcrl"
          placeholder="请输入本期完成容量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期完成总价" prop="bqWczj">
        <el-input
          v-model="queryParams.bqWczj"
          placeholder="请输入本期完成总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期支付预付款" prop="bqZfyfk">
        <el-input
          v-model="queryParams.bqZfyfk"
          placeholder="请输入本期支付预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期扣除预付款" prop="bqKcyfk">
        <el-input
          v-model="queryParams.bqKcyfk"
          placeholder="请输入本期扣除预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期扣款" prop="bqLjkk">
        <el-input
          v-model="queryParams.bqLjkk"
          placeholder="请输入本期扣款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="本期付款金额" prop="bqFk">
        <el-input
          v-model="queryParams.bqFk"
          placeholder="请输入本期付款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已完成容量" prop="jzbqyWcrl">
        <el-input
          v-model="queryParams.jzbqyWcrl"
          placeholder="请输入截止本期已完成容量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已完成总价" prop="jzbqyWczj">
        <el-input
          v-model="queryParams.jzbqyWczj"
          placeholder="请输入截止本期已完成总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已支付预付款" prop="jzbqyZfyfk">
        <el-input
          v-model="queryParams.jzbqyZfyfk"
          placeholder="请输入截止本期已支付预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已扣除预付款" prop="jzbqyKcyfk">
        <el-input
          v-model="queryParams.jzbqyKcyfk"
          placeholder="请输入截止本期已扣除预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已扣款" prop="jzbqyLjkk">
        <el-input
          v-model="queryParams.jzbqyLjkk"
          placeholder="请输入截止本期已扣款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期已付款金额" prop="jzbqyFk">
        <el-input
          v-model="queryParams.jzbqyFk"
          placeholder="请输入截止本期已付款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止本期付款比例" prop="jzbqFkbl">
        <el-input
          v-model="queryParams.jzbqFkbl"
          placeholder="请输入截止本期付款比例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已完成容量" prop="jzsqyWcrl">
        <el-input
          v-model="queryParams.jzsqyWcrl"
          placeholder="请输入截止上期已完成容量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已完成总价" prop="jzsqyWczj">
        <el-input
          v-model="queryParams.jzsqyWczj"
          placeholder="请输入截止上期已完成总价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已支付预付款" prop="jzsqyZfyfk">
        <el-input
          v-model="queryParams.jzsqyZfyfk"
          placeholder="请输入截止上期已支付预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已扣除预付款" prop="jzsqyKcyfk">
        <el-input
          v-model="queryParams.jzsqyKcyfk"
          placeholder="请输入截止上期已扣除预付款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已扣款" prop="jzsqyLjkk">
        <el-input
          v-model="queryParams.jzsqyLjkk"
          placeholder="请输入截止上期已扣款"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期已付款金额" prop="jzsqyFk">
        <el-input
          v-model="queryParams.jzsqyFk"
          placeholder="请输入截止上期已付款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="截止上期付款比例" prop="jzsqFkbl">
        <el-input
          v-model="queryParams.jzsqFkbl"
          placeholder="请输入截止上期付款比例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['cm:baSettleDetail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['cm:baSettleDetail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['cm:baSettleDetail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cm:baSettleDetail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baSettleDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="计量单主表id" align="center" prop="settleId" />
      <el-table-column label="清单项计量id" align="center" prop="settleDetailId" v-if="true"/>
      <el-table-column label="合同清单项id" align="center" prop="cSheetId" />
      <el-table-column label="本期完成容量" align="center" prop="bqWcrl" />
      <el-table-column label="本期完成总价" align="center" prop="bqWczj" />
      <el-table-column label="本期支付预付款" align="center" prop="bqZfyfk" />
      <el-table-column label="本期扣除预付款" align="center" prop="bqKcyfk" />
      <el-table-column label="本期扣款" align="center" prop="bqLjkk" />
      <el-table-column label="本期付款金额" align="center" prop="bqFk" />
      <el-table-column label="截止本期已完成容量" align="center" prop="jzbqyWcrl" />
      <el-table-column label="截止本期已完成总价" align="center" prop="jzbqyWczj" />
      <el-table-column label="截止本期已支付预付款" align="center" prop="jzbqyZfyfk" />
      <el-table-column label="截止本期已扣除预付款" align="center" prop="jzbqyKcyfk" />
      <el-table-column label="截止本期已扣款" align="center" prop="jzbqyLjkk" />
      <el-table-column label="截止本期已付款金额" align="center" prop="jzbqyFk" />
      <el-table-column label="截止本期付款比例" align="center" prop="jzbqFkbl" />
      <el-table-column label="截止上期已完成容量" align="center" prop="jzsqyWcrl" />
      <el-table-column label="截止上期已完成总价" align="center" prop="jzsqyWczj" />
      <el-table-column label="截止上期已支付预付款" align="center" prop="jzsqyZfyfk" />
      <el-table-column label="截止上期已扣除预付款" align="center" prop="jzsqyKcyfk" />
      <el-table-column label="截止上期已扣款" align="center" prop="jzsqyLjkk" />
      <el-table-column label="截止上期已付款金额" align="center" prop="jzsqyFk" />
      <el-table-column label="截止上期付款比例" align="center" prop="jzsqFkbl" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cm:baSettleDetail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['cm:baSettleDetail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改计量详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="计量单主表id" prop="settleId">
          <el-input v-model="form.settleId" placeholder="请输入计量单主表id" />
        </el-form-item>
        <el-form-item label="合同清单项id" prop="cSheetId">
          <el-input v-model="form.cSheetId" placeholder="请输入合同清单项id" />
        </el-form-item>
        <el-form-item label="本期完成容量" prop="bqWcrl">
          <el-input v-model="form.bqWcrl" placeholder="请输入本期完成容量" />
        </el-form-item>
        <el-form-item label="本期完成总价" prop="bqWczj">
          <el-input v-model="form.bqWczj" placeholder="请输入本期完成总价" />
        </el-form-item>
        <el-form-item label="本期支付预付款" prop="bqZfyfk">
          <el-input v-model="form.bqZfyfk" placeholder="请输入本期支付预付款" />
        </el-form-item>
        <el-form-item label="本期扣除预付款" prop="bqKcyfk">
          <el-input v-model="form.bqKcyfk" placeholder="请输入本期扣除预付款" />
        </el-form-item>
        <el-form-item label="本期扣款" prop="bqLjkk">
          <el-input v-model="form.bqLjkk" placeholder="请输入本期扣款" />
        </el-form-item>
        <el-form-item label="本期付款金额" prop="bqFk">
          <el-input v-model="form.bqFk" placeholder="请输入本期付款金额" />
        </el-form-item>
        <el-form-item label="截止本期已完成容量" prop="jzbqyWcrl">
          <el-input v-model="form.jzbqyWcrl" placeholder="请输入截止本期已完成容量" />
        </el-form-item>
        <el-form-item label="截止本期已完成总价" prop="jzbqyWczj">
          <el-input v-model="form.jzbqyWczj" placeholder="请输入截止本期已完成总价" />
        </el-form-item>
        <el-form-item label="截止本期已支付预付款" prop="jzbqyZfyfk">
          <el-input v-model="form.jzbqyZfyfk" placeholder="请输入截止本期已支付预付款" />
        </el-form-item>
        <el-form-item label="截止本期已扣除预付款" prop="jzbqyKcyfk">
          <el-input v-model="form.jzbqyKcyfk" placeholder="请输入截止本期已扣除预付款" />
        </el-form-item>
        <el-form-item label="截止本期已扣款" prop="jzbqyLjkk">
          <el-input v-model="form.jzbqyLjkk" placeholder="请输入截止本期已扣款" />
        </el-form-item>
        <el-form-item label="截止本期已付款金额" prop="jzbqyFk">
          <el-input v-model="form.jzbqyFk" placeholder="请输入截止本期已付款金额" />
        </el-form-item>
        <el-form-item label="截止本期付款比例" prop="jzbqFkbl">
          <el-input v-model="form.jzbqFkbl" placeholder="请输入截止本期付款比例" />
        </el-form-item>
        <el-form-item label="截止上期已完成容量" prop="jzsqyWcrl">
          <el-input v-model="form.jzsqyWcrl" placeholder="请输入截止上期已完成容量" />
        </el-form-item>
        <el-form-item label="截止上期已完成总价" prop="jzsqyWczj">
          <el-input v-model="form.jzsqyWczj" placeholder="请输入截止上期已完成总价" />
        </el-form-item>
        <el-form-item label="截止上期已支付预付款" prop="jzsqyZfyfk">
          <el-input v-model="form.jzsqyZfyfk" placeholder="请输入截止上期已支付预付款" />
        </el-form-item>
        <el-form-item label="截止上期已扣除预付款" prop="jzsqyKcyfk">
          <el-input v-model="form.jzsqyKcyfk" placeholder="请输入截止上期已扣除预付款" />
        </el-form-item>
        <el-form-item label="截止上期已扣款" prop="jzsqyLjkk">
          <el-input v-model="form.jzsqyLjkk" placeholder="请输入截止上期已扣款" />
        </el-form-item>
        <el-form-item label="截止上期已付款金额" prop="jzsqyFk">
          <el-input v-model="form.jzsqyFk" placeholder="请输入截止上期已付款金额" />
        </el-form-item>
        <el-form-item label="截止上期付款比例" prop="jzsqFkbl">
          <el-input v-model="form.jzsqFkbl" placeholder="请输入截止上期付款比例" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaSettleDetail, getBaSettleDetail, delBaSettleDetail, addBaSettleDetail, updateBaSettleDetail } from "@/api/cm/baSettleDetail";

export default {
  name: "BaSettleDetail",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 计量详情表格数据
      baSettleDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        settleId: undefined,
        cSheetId: undefined,
        bqWcrl: undefined,
        bqWczj: undefined,
        bqZfyfk: undefined,
        bqKcyfk: undefined,
        bqLjkk: undefined,
        bqFk: undefined,
        jzbqyWcrl: undefined,
        jzbqyWczj: undefined,
        jzbqyZfyfk: undefined,
        jzbqyKcyfk: undefined,
        jzbqyLjkk: undefined,
        jzbqyFk: undefined,
        jzbqFkbl: undefined,
        jzsqyWcrl: undefined,
        jzsqyWczj: undefined,
        jzsqyZfyfk: undefined,
        jzsqyKcyfk: undefined,
        jzsqyLjkk: undefined,
        jzsqyFk: undefined,
        jzsqFkbl: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        settleId: [
          { required: true, message: "计量单主表id不能为空", trigger: "blur" }
        ],
        settleDetailId: [
          { required: true, message: "清单项计量id不能为空", trigger: "blur" }
        ],
        cSheetId: [
          { required: true, message: "合同清单项id不能为空", trigger: "blur" }
        ],
        bqWcrl: [
          { required: true, message: "本期完成容量不能为空", trigger: "blur" }
        ],
        bqWczj: [
          { required: true, message: "本期完成总价不能为空", trigger: "blur" }
        ],
        bqZfyfk: [
          { required: true, message: "本期支付预付款不能为空", trigger: "blur" }
        ],
        bqKcyfk: [
          { required: true, message: "本期扣除预付款不能为空", trigger: "blur" }
        ],
        bqLjkk: [
          { required: true, message: "本期扣款不能为空", trigger: "blur" }
        ],
        bqFk: [
          { required: true, message: "本期付款金额不能为空", trigger: "blur" }
        ],
        jzbqyWcrl: [
          { required: true, message: "截止本期已完成容量不能为空", trigger: "blur" }
        ],
        jzbqyWczj: [
          { required: true, message: "截止本期已完成总价不能为空", trigger: "blur" }
        ],
        jzbqyZfyfk: [
          { required: true, message: "截止本期已支付预付款不能为空", trigger: "blur" }
        ],
        jzbqyKcyfk: [
          { required: true, message: "截止本期已扣除预付款不能为空", trigger: "blur" }
        ],
        jzbqyLjkk: [
          { required: true, message: "截止本期已扣款不能为空", trigger: "blur" }
        ],
        jzbqyFk: [
          { required: true, message: "截止本期已付款金额不能为空", trigger: "blur" }
        ],
        jzbqFkbl: [
          { required: true, message: "截止本期付款比例不能为空", trigger: "blur" }
        ],
        jzsqyWcrl: [
          { required: true, message: "截止上期已完成容量不能为空", trigger: "blur" }
        ],
        jzsqyWczj: [
          { required: true, message: "截止上期已完成总价不能为空", trigger: "blur" }
        ],
        jzsqyZfyfk: [
          { required: true, message: "截止上期已支付预付款不能为空", trigger: "blur" }
        ],
        jzsqyKcyfk: [
          { required: true, message: "截止上期已扣除预付款不能为空", trigger: "blur" }
        ],
        jzsqyLjkk: [
          { required: true, message: "截止上期已扣款不能为空", trigger: "blur" }
        ],
        jzsqyFk: [
          { required: true, message: "截止上期已付款金额不能为空", trigger: "blur" }
        ],
        jzsqFkbl: [
          { required: true, message: "截止上期付款比例不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询计量详情列表 */
    getList() {
      this.loading = true;
      listBaSettleDetail(this.queryParams).then(response => {
        this.baSettleDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        settleId: undefined,
        settleDetailId: undefined,
        cSheetId: undefined,
        bqWcrl: undefined,
        bqWczj: undefined,
        bqZfyfk: undefined,
        bqKcyfk: undefined,
        bqLjkk: undefined,
        bqFk: undefined,
        jzbqyWcrl: undefined,
        jzbqyWczj: undefined,
        jzbqyZfyfk: undefined,
        jzbqyKcyfk: undefined,
        jzbqyLjkk: undefined,
        jzbqyFk: undefined,
        jzbqFkbl: undefined,
        jzsqyWcrl: undefined,
        jzsqyWczj: undefined,
        jzsqyZfyfk: undefined,
        jzsqyKcyfk: undefined,
        jzsqyLjkk: undefined,
        jzsqyFk: undefined,
        jzsqFkbl: undefined,
        createBy: undefined,
        updateBy: undefined,
        updateTime: undefined,
        createTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.settleDetailId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加计量详情";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const settleDetailId = row.settleDetailId || this.ids
      getBaSettleDetail(settleDetailId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改计量详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.settleDetailId != null) {
            updateBaSettleDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addBaSettleDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const settleDetailIds = row.settleDetailId || this.ids;
      this.$modal.confirm('是否确认删除计量详情编号为"' + settleDetailIds + '"的数据项？').then(() => {
        this.loading = true;
        return delBaSettleDetail(settleDetailIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cm/baSettleDetail/export', {
        ...this.queryParams
      }, `baSettleDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
